const Service = require('../../../core/service/ApiService');

class StaffDao extends Service {

    //登录用
    async findStaffByAccount(phone) {
        return this.model.ServiceStaff.findOne({
            where: {
                phone: phone,
                status: this.constant.STAFF_STATUS.ENABLE
            }, attributes: ['svc_staff_id', 'phone', 'pwd', 'community_id_list'],
            raw: true
        })
    }

    //修改密码
    async updateStaffPwd(staff_id, pwd) {
        return this.model.ServiceStaff.update({
            pwd: pwd
        }, {
            where: {
                svc_staff_id: staff_id
            }
        })
    }

    async getStaffPwd(id) {
        const s = await this.model.ServiceStaff.findOne({
            where: {
                svc_staff_id: id
            },
            attributes: ['pwd'],
            raw: true
        });
        return s !== null ? s.pwd : null;
    }

    //获取服务人员信息
    async getStaffInfo(id) {
        return this.model.ServiceStaff.findOne({
            where: {
                svc_staff_id: id
            },
            attributes: ['name', 'score', 'pic', 'cur_month_svc_cnt'],
            raw: true
        })
    }


}

module.exports = StaffDao;

